<?php
/**
 * 作者: NewYear
 * 创建日期: 2019/8/30 10:05
 * 简介: 应用异常错误处理
 */

namespace Core\Exception;
use Core\Service\Response;
use Illuminate\Http\Exceptions\HttpResponseException;

/**
 * 程序错误响应
 */
class AppException extends HttpResponseException
{
    protected $title = "";
    protected $message = "";
    protected $code = "";
    protected $data = "";

    public function __construct($message = "", $code = 1, $data = null,$url = "")
    {
        $this->setMessage($message);
        $this->setCode($code);
        $this->setData($data);
//        $this->response = Response::error($message, $code ,$data, $url, "",[],false);
        $this->response = Response::exception($this);
        parent::__construct($this->getResponse());
    }

    /**
     * @param $message
     * @return mixed
     */
    public function setMessage($message)
    {
        $this->message = $message;
    }


    /**
     * @param $code
     * @return string
     */
    public function setCode($code)
    {
        $this->code = $code;
    }


    /**
     * @return string
     */
    public function getData()
    {
        return $this->data;
    }

    /**
     * @param string $data
     */
    public function setData($data)
    {
        $this->data = $data;
    }
}